package cn.midas.system.controller;

import cn.midas.basic.utils.AjaxResult;
import cn.midas.basic.utils.PageList;
import cn.midas.system.domain.Deta;
import cn.midas.system.query.DetaQuery;
import cn.midas.system.service.IDetaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "部门的API",description="部门相关的CRUD功能")
@RestController
@RequestMapping("/deta")
public class DetaController {
    @Autowired
   private IDetaService detaService;

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public Deta loadById(@ApiParam(value="t_dict表主键",required = true) @PathVariable("id") Long id) {
        return detaService.loadById(id);
    }

    @GetMapping
    public List<Deta> loadAll() {
        return detaService.loadAll();
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {

        try {
            detaService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试!");
        }
    }

    @PutMapping
    public AjaxResult uptOrAdd(@RequestBody Deta deta) {
        try {
            if (deta.getId()==null) {
                detaService.save(deta);
            }else {
                detaService.update(deta);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试!");
        }


    }
    @PostMapping
    public PageList<Deta> queryData(@RequestBody DetaQuery detaQuery) {
        return detaService.queryData(detaQuery);
    }

    @PatchMapping
    public AjaxResult batchDel(@RequestBody Long[] ids) {

        try {
            detaService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试!");
        }
    }



}
